package com.xuecheng.user.context;

import com.xuecheng.user.exception.AuthTypeNotExistException;
import com.xuecheng.user.factory.AuthServiceFactory;
import com.xuecheng.user.model.dto.AuthParamsDTO;
import com.xuecheng.user.model.dto.XcUserExt;
import com.xuecheng.user.service.AuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author 勾新杰
 * @version 1.0
 * @description: 认证服务上下文
 * @date 2025/4/12 13:01
 */
@Component
@RequiredArgsConstructor
public class AuthServiceContext {

    /**
     * 认证服务工厂
     */
    private final AuthServiceFactory authServiceFactory;

    /**
     * 认证方法
     *
     * @param authParamsDTO 认证参数
     * @return XcUserExt
     */
    public XcUserExt auth(AuthParamsDTO authParamsDTO){
        AuthService authService = authServiceFactory.getService(authParamsDTO.getAuthType());
        if (authService == null) AuthTypeNotExistException.cast();
        return authService.auth(authParamsDTO);
    }
}
